import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 注意，path以 / 开头的嵌套路径将被视为根路径。这允许你利用组件嵌套，而不必使用嵌套的 URL。
const routes = [
    {
        path: '/login',
        component: () => import(/* webpackChunkName: "about" */ '../views/systemCommonPage/Login.vue')
    },
    {
        path: '/notFound',
        component: () => import(/* webpackChunkName: "about" */ '../views/systemCommonPage/NotFound.vue')
    },
    {
        path: '/backstageManager',
        name: 'BackstageManagerPage',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/BackstageManagerPage.vue'),
    },
    {
        path: '/backstageManager/dragGroupOneWay',
        name: 'DragGroupOneWay',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/drag/DragGroupOneWay.vue')
    },
    {
        path: '/backstageManager/dragGroupTwoWay',
        name: 'DragGroupTwoWay',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/drag/DragGroupTwoWay.vue')
    },
    {
        path: '/backstageManager/dragSort',
        name: 'DragSort',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/drag/DragSort.vue')
    },
    /** 地图 */
    {
        path: '/backstageManager/openLayers/basic/demo1',
        name: 'OpenLayersDemo1',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/openLayers/basic/Demo1.vue')
    },
    {
        path: '/backstageManager/openLayers/basic/demo2',
        name: 'OpenLayersDemo2',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/openLayers/basic/Demo2.vue')
    },
    {
        path: '/backstageManager/openLayers/basic/demo3',
        name: 'OpenLayersDemo3',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/openLayers/basic/Demo3.vue')
    },
    {
        path: '/backstageManager/openLayers/control/FullScreen',
        name: 'OpenLayersFullScreen',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/openLayers/control/FullScreen.vue')
    },
    {
        path: '/backstageManager/openLayers/interaction/MeasureDemo',
        name: 'OpenLayersMeasureDemo',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/openLayers/interaction/MeasureDemo.vue')
    },
    // js进阶
    {
        path: '/backstageManager/js/method/Array',
        name: 'JsArray',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/js/method/Array.vue')
    },
    {
        path: '/backstageManager/js/method/Function',
        name: 'JsFunction',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/js/method/Function.vue')
    },
    {
        path: '/js/method/window/window',
        name: 'JsWindow',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/js/method/window/Window.vue')
    },
    {
        path: '/backstageManager/js/method/window/newWindow',
        name: 'newWindow',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/js/method/window/NewWindow.vue')
    },
    {
        path: '/backstageManager/js/prototype/Prototype',
        name: 'JsPrototype',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/js/prototype/Prototype.vue')
    },
    {
        path: '/backstageManager/js/clazz/Clazz',
        name: 'Jsclazz',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/js/clazz/Clazz.vue')
    },
    {
        path: '/backstageManager/js/module/Module',
        name: 'Module',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/js/module/Module.vue')
    },

    {
        path: '/backstageManager/elementui/Upload',
        name: 'Upload',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/elementui/Upload.vue')
    },
    {
        path: '/backstageManager/elementui/Select',
        name: 'Select',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/elementui/Select.vue')
    },
    {
        path: '/backstageManager/elementui/EditableTree',
        name: 'EditableTree',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/elementui/EditableTree.vue')
    },
    {
        path: '/backstageManager/elementui/ScrollLoad',
        name: 'ScrollLoad',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/elementui/ScrollLoad.vue')
    },
    // vue相关
    {
        path: '/backstageManager/vue/eventBus/EventBus',
        name: 'EventBus',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/vue/eventBus/EventBus.vue')
    },
    {
        path: '/backstageManager/vue/executeJs/executeNoExportJs',
        name: 'EventBus',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/vue/executeJs/executeNoExportJs.vue')
    },
    // gojs
    // {
    //     path: '/backstageManager/vue/gojs/GoJsHelloworld',
    //     name: 'GoJsHelloworld',
    //     component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/gojs/GoJsHelloworld.vue')
    // },
    // {
    //     path: '/backstageManager/vue/gojs/GoJsBasic',
    //     name: 'GoJsBasic',
    //     component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/gojs/GoJsBasic.vue')
    // },
    // 关联图
    {
        path: '/backstageManager/vue/graph/gojs/QuickStart',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/gojs/QuickStart.vue')
    },
    {
        path: '/backstageManager/vue/graph/gojs/DragGeneratorNode',
        name: 'DragGeneratorNode',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/gojs/DragGeneratorNode.vue')
    },
    {
        path: '/backstageManager/vue/graph/gojs/DrawLink',
        name: 'DrawLink',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/gojs/DrawLink.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4AdvDataFilter',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4AdvDataFilter.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4AdvDynamicData',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4AdvDynamicData.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4AdvEffect',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4AdvEffect.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4AdvMultiLayout',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4AdvMultiLayout.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4AdvNodeTips',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4AdvNodeTips.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4AdvSlot',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4AdvSlot.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4Arrow',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4Arrow.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4BothwayTree',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4BothwayTree.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4CenterDistanceCoefficient',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4CenterDistanceCoefficient.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4Expand',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4Expand.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4ExpandGradually',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4ExpandGradually.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4Graph',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4Graph.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4GraphResize',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4GraphResize.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4Hide2Show',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4Hide2Show.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4LayoutCenter',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4LayoutCenter.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4LayoutForce',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4LayoutForce.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4LayoutTree',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4LayoutTree.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4LayoutTree2',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4LayoutTree2.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4Line',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4Line.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4Logo',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4Logo.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4Node',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4Node.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4SceneCompany',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4SceneCompany.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4SceneGroup',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4SceneGroup.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4SceneNetwork',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4SceneNetwork.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4SceneOrg',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4SceneOrg.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4SceneRelationship',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4SceneRelationship.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4TreeData',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4TreeData.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/Demo4TreeDistance',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/Demo4TreeDistance.vue')
    },
    {
        path: '/backstageManager/vue/graph/relationGraph/DemoStudy',
        name: 'Demo4Graph',
        component: () => import(/* webpackChunkName: "about" */ '../views/backstageManager/graph/relationGraph/DemoStudy.vue')
    },

]

const router = new VueRouter({
    mode: 'history', // history模式
    base: process.env.BASE_URL,
    routes: routes
})

const whiteList = ['/error', '/register/regindex', '/register/userauthent', '/register/submit'] // 路由白名单
/**
 * 导航守卫前置方法。
 * 参考博客：https://www.jianshu.com/p/c9e9aa4c75f2
 * @param to 要跳转到哪一个页面
 * @param from 从哪一个页面跳转而来
 * @param next 责任链，调用该方法触发下一个责任链
 */
router.beforeEach((to, from, next) => {
    // 如果访问项目的根目录，跳转到登陆页
    if (to.path == "/") {
        next({ path: '/login', replace: true, query: {} })
    }
    // 如果访问不合法的路由，跳转到页面不存在页面
    else if (routes.findIndex(item => item.path == to.path) == -1) {
        next({ path: '/notFound', replace: true, query: {} })
    }
    // 记得当所有程序执行完毕后要进行next()，不然是无法继续进行的;
    next();
})

export default router
